<?php
/**
 * Created by PhpStorm.
 * User: yandian
 * Date: 16/8/15
 * Time: 10:48
 */

namespace app\admin\services;


use app\common\services\BaseService;

class WeixinMenuService extends BaseService
{
    public function __construct()
    {
        parent::__construct('', '(select w1.*,w2.title parent_title from weixin_menu w1 left join weixin_menu w2 on w1.parent_id=w2.id) t');
    }

    public function pagination($page, $rows, $sort, $order, $filterRules)
    {
        $viewInstance = $this->_getViewInstance();
        $pid = I('pid', 0, 'intval');
        $filterRules = $this->parseFilterRules($filterRules);
        return [
            $viewInstance->where($filterRules)->where("parent_id=$pid or id=$pid")->count(),
            $viewInstance->where($filterRules)->where("parent_id=$pid or id=$pid")->limit(($page - 1) * $rows, $rows)->select()
        ];
    }
}